package com.lcxw.hxzbapi.dao.mapper;

import com.lcxw.hxzbapi.entity.pojo.Attention;
import java.util.List;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

@Component
@Mapper
@Service
public interface AttentionMapper {

    /**
     * 通过userId来查询该用户关注了哪些用户
     */
    @Select("SELECT attuid FROM ywpd_attention WHERE userid = #{userId} AND attype = 'member'")
    List<Long> selectAttuidByUserId(long userId);

    @Select("SELECT attuid FROM ywpd_attention WHERE userid = #{userId} AND attype = 'room'")
    List<Long> selectAttroomidByUserId(long userId);

    /**
     * 通过attuid来查询该用户被多少人关注
     */
    @Select("SELECT COUNT(attuid) FROM ywpd_attention WHERE attuid = #{attuid}")
    int selectCountOfAttuid(long attuid) throws Exception;

    /**
     * 添加一个关注的人
     */
    @Insert("INSERT INTO ywpd_attention (userid,attuid,attype,addtime) VALUES (#{userId},#{attuId},#{attype},#{addTime})")
    int addAttentionUser(long userId, long attuId, String attype, String addTime) throws Exception;

    @Delete("DELETE FROM ywpd_attention where userid=#{userId} and attuid=#{attuId} and attype=#{attype}")
    int deleteAttentionUser(long userId, long attuId, String attype) throws Exception;

    @Select("SELECT * FROM ywpd_attention WHERE userid=#{userId} and attuid=#{attuId} and attype=#{attype}")
    Attention getAttentionByUserIdAndAttuId(long userId, long attuId, String attype);

    @Select("SELECT userId FROM ywpd_attention WHERE  attuid=#{attuId} and attype=#{attype}")
    List<Long> getFans(long attuId, String attype);

    /**
     * 查询粉丝数量
     */
    @Select("SELECT COUNT(*) FROM ywpd_attention WHERE attuid=#{attuId} AND attype = 'member'")
    int getFansNum(long attuId);
}
